# -*- coding: UTF-8 -*-

import httplib
import urllib

host = "localhost"
port = 8080

username = "username"
password = "password"

auth = "Basic " + (username + ":" + password).encode("base64").rstrip('\n')

def user():
    headers = {"Authorization":auth}
    h = httplib.HTTPConnection(host, port)
    h.request("GET", "/v1/user.json", None, headers=headers)
    r = h.getresponse()
    h.close()
    if r.status == 200:
        print "user pass", r.read()
        return True
    else:
        print "user fail", r.read()
        return False

def checkin():
    h = httplib.HTTPConnection(host, port)
    data = "shout=test"
    headers = {"Authorization":auth}
    h.request("POST", "/v1/checkin.json", body=data, headers = headers)
    r = h.getresponse()
    h.close()
    if r.status == 200:
        str = r.read()
        print "user pass", len(str), str
        return True
    else:
        print "user fail", r.read()
        return False
    
def main():
    user()
    checkin()
    
if __name__ == "__main__":
    main()